import {GET,POST} from '@/request/request.js';
const openid = () => {
	return new Promise((resolve, reject) => {
		let openid = uni.getStorageSync("openid");
		if(openid){
			resolve(openid)
		}else{
			uni.login({
				success(res) {
					if (res.code) {
						POST('/users/getWxOpenid.htm',{code:res.code},false).then(res=>{
								let openid = res.data.data;
								uni.setStorageSync("openid",openid)
								resolve(openid)
						}).catch(err=>{
							reject(err);
						})
					} else {
						reject(res.errMsg);
					}
				}
			
			})
		}

	})
}

export default {
	openid
}